import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter

root = ET.parse("D:\\StarCraft\\bwapi-data\\logs\\g.xml").getroot()
generations = root.findall("generation")

avg_obj = [[],[],[],[]]

for gen in generations:
	for o in avg_obj: o.append(0)
	for g in gen.findall("genome"):
		i = 0
		for o in g.findall("objective"):
			curr_val = avg_obj[i][len(avg_obj[i])-1]
			val = float(o.get("fitness"))
			
			if val > curr_val: 
				avg_obj[i][len(avg_obj[i])-1] = val
				
			i += 1

plt.ylabel("generations")
plt.subplot(221).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.title("objective 1")
plt.plot(avg_obj[0])
plt.subplot(222).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.title("objective 2")
plt.plot(avg_obj[1])
plt.subplot(223).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.title("objective 3")
plt.plot(avg_obj[2])
plt.subplot(224).xaxis.set_major_formatter(FormatStrFormatter('%0.0f'))
plt.title("objective 4")
plt.plot(avg_obj[3])
plt.show()

